import common from '@/common/js/common';
import throttle from '@/common/js/throttle.js';
export const mixinsBase = {
    data() {
        return {
            ready: true,
            barStyle: {
                background: '#e5d29c',
                height: '6px',
                bottom: '4px',
                borderRadius: 0,
                width: '20px'
            },
			isLoading:false,
        }
    },
    onShow(){
        // #ifdef H5
        this.$common.h5SetTitle('');
        // #endif
    },
    methods: {
        confirm(e, name) {
            const date = e[0]
            this[name] = date;
        },
        link(url,isLogin=false){
            this.$common.link(url, isLogin);
        },
        goback(){
            this.$common.goback();
        }
    }
}

export const mixinsSpot = {
    data() {
        return {
           navCur:0,
            scrollTop:0,
            tag:[],
            scrollTag:false,
            showTag:true,
            showNavtop:false,
            argShow:false,
             navtop:this.$config.NAVTOP,
            info:{
                active:false,
            },
            adlist: [
                {
                    image: '/static/ad/st14.png',
                    title: '昨夜星辰昨夜风，画楼西畔桂堂东'
                },
                {
                    image: 'https://cdn.uviewui.com/uview/swiper/2.jpg',
                    title: '身无彩凤双飞翼，心有灵犀一点通'
                },
                {
                    image: 'https://cdn.uviewui.com/uview/swiper/3.jpg',
                    title: '谁念西风独自凉，萧萧黄叶闭疏窗，沉思往事立残阳'
                }
            ],
           content: `
                   <p>露从今夜白，月是故乡明</p>
                   <img src="https://cdn.uviewui.com/uview/swiper/2.jpg" />
                  <img src="https://cdn.uviewui.com/uview/swiper/1.jpg" />
                  <img src="https://cdn.uviewui.com/uview/swiper/3.jpg" />
               `,
               btnStyle: this.$config.btnStyle,
        }
    },
    
   onPageScroll: throttle(function(e) {
            if (!e) return;
          let scrollTop = e.scrollTop;
          this.scrollTop = e.scrollTop;
          if (scrollTop > 0 && !this.showNavtop) {
              this.showNavtop = true;
              //#ifdef APP-PLUS
              plus.navigator.setStatusBarStyle('dark');
              //#endif
               this.navtop = this.$config.NAVTOP_ACTIVE;
          }
          if (scrollTop == 0) {
              this.showNavtop = false;
              //#ifdef APP-PLUS
              plus.navigator.setStatusBarStyle('light');
              //#endif
               this.navtop = this.$config.NAVTOP;
          }
          //导航
          if(!this.scrollTag && this.showTag){
              const tag = this.tag
              for(let i=0,l=tag.length;i<l;i++){
                  if( scrollTop < tag[i] && i == 0 || tag[i] <= scrollTop && tag[i+1] > scrollTop || tag[i] > scrollTop){
                      this.navCur = i
                      break
                  }
              }
          }
    }, 40),
    methods: {
        async scrollNavTop(index){
            if(this.scrollTag)return;
            if(index === this.navCur)return;
            const that = this;
            this.scrollTag = true
            uni.pageScrollTo({
                scrollTop:this.tag[index],
                duration:300,
                success(){
                    setTimeout(()=>{
                        console.log('index', index)
                        that.navCur = index;
                        that.$nextTick(()=>{
                            that.scrollTag = false
                        })
                    }, 700)
                },
            })
        },
        async caleInit(){
           this.tag = [];
           let list = await this.$u.getRect('.tag', true);
           let top = this.$config.statusbarHeight + this.$config.navbarHeight +uni.upx2px(80);
           this.tag = list.map(item=>item.top-top);
        },
    },
    computed: {
        //导航高度
        navtopListStyle(){
            let style = {
                top:this.$config.statusbarHeight + this.$config.navbarHeight + 'px'
            }
            return style
        },
    }
}
